def index():
    return dict()

def auth_test():
#    auth_test = sip.auth.getSession()
    auth_url = taobao_api.get_url(login_keys_list, session.sip_dict, SIP_LOGIN_URL, False)
    logger('auth_url', auth_url)
#    redirect(auth_url)

    return dict(
        auth_url = auth_url,
        )

def bought_test():
    sip_sessionid = session.sip_dict['sip_sessionid']
    bought = sip.taobao.trades.bought.get(sip_sessionid, fields = ['title', 'iid', 'tid'])
    return dict(
        bought = bought,
        )
        
def taobao_products_test():
    products = sip.taobao.products.search(fields = ['product_id', 'props', 'props_str', 'cat_name', 'name', 'sale_props_str', 'binds_str', 'price', 'modified', 'pic_path'], q='pc')
    return dict(
        products = products,
        )
        
def ali_items_test():
#    sip_dict = sip.__dict__

    appInstanceId = session.sip_dict['appInstanceId']
    token = session.sip_dict['token']
    userId = session.sip_dict['userId']

    validateUser = sip.alisoft.validateUser(appId, appInstanceId, userId, token)
    validateAppUser  = sip.alisoft.validateAppUser(appId, appInstanceId, userId)

    items_get = sip.taobao.items.get(fields=['iid','title','nick','pic_path','cid','price','type','location.city','delist_time','post_fee'], q='笔记本', page_no='121', start_price='199', end_price='1900', ww_status='true', page_size='5', order_by='price:desc')
    iid_get = sip.taobao.item.get(fields=['iid','title','nick','pic_path','cid','price','type','location.city','delist_time','post_fee'], iid='62988750ce0769570d7567e12d4f156b', nick='绿匣子数码旗舰店')
#    items_get = sip.taobao.items.get.location(city='北京')
#    items_instock_get = sip.taobao.items.instock.get(fields=['iid', 'title', 'nick'], q='nike',)
    
    return dict(
#        sip_dict = sip_dict,
        validateUser = validateUser,
        validateAppUser = validateAppUser,

        items_get = items_get,
        iid_get = iid_get
#        items_instock_get = items_instock_get,
        )

def db_test():
    form = [i.api for i in db().select(db.interface.ALL)]
    return dict(
        form = form,
        )

def start_test():
    if not session.user_name:
        if session.sip_dict:
            sip_dict = session.sip_dict
            sip_dict['sip_apiname'] = 'alisoft.validateUser'
            validate_user_url = taobao_api.get_url(validate_user_keys_list, sip_dict, sip_sign=True)
            validate_user_rsp = fetch(validate_user_url)
            validate_user_xml = minidom.parseString(validate_user_rsp)
#            # temp list
#            session.SIP = sip.alisoft.validateUser(appId=sip_dict['appId'], appInstanceId=sip_dict['appInstanceId'],userId=sip_dict['userId'],token=sip_dict['token'])

            if validate_user_xml.getElementsByTagName("String")[0].firstChild.nodeValue == '1':
                sip_dict['sip_apiname'] = 'alisoft.udb.getDomainLoginId'
                get_domain_login_id_url = taobao_api.get_url(get_domain_login_id_keys_list, sip_dict, sip_sign=True)
                get_domain_login_id_rsp = fetch(get_domain_login_id_url)
                get_domain_login_id_xml = minidom.parseString(get_domain_login_id_rsp)
#                get_domain_login_id_json = simplejson.loads(get_domain_login_id_rsp)
                session.user_name = get_domain_login_id_xml.getElementsByTagName("result")[0].firstChild.nodeValue
#                session.user_name = get_domain_login_id_json
                redirect(URL(r=request, c = 'default'))
        else:
            redirect(URL(r=request, c = 'default'))
    else:
        redirect(URL(r=request, c = 'default'))

#    sip_login_url = taobao_api.sip_url(login_keys_list, sip_dict)
#    sip_login_url = SIPLOGIN_URL + '?' + sip_login_url
#
#    validate_user_sign = taobao_api.sip_sign(validate_user_keys_list, sip_dict)
#    validate_user_url = taobao_api.sip_url(validate_user_keys_list, sip_dict)
#    validate_user_url = SIP_REST_URL + '?' + validate_user_url + 'sip_sign=' + validate_user_sign

    return dict(
        )
